package com.idealighter.game.games.horserace.struct;

import com.idealighter.utils.code.RandCodeUtil;

import java.util.ArrayList;
import java.util.List;

public class Horse {

  public static final int V = 1000;
  public static final int N = 1;
  private int id;
  private int segment;
  private int totalTime;
  private List<Integer> perTime = new ArrayList<>();

  public int getSegment() {
    return segment;
  }

  public void setSegment(int segment) {
    this.segment = segment;
  }

  public int getId() {
    return id;
  }

  public void setId(int id) {
    this.id = id;
  }

  public int getTotalTime() {
    return totalTime;
  }

  public void setTotalTime(int totalTime) {
    this.totalTime = totalTime;
  }

  public List<Integer> getPerTime() {
    return perTime;
  }

  public void setPerTime(List<Integer> perTime) {
    this.perTime = perTime;
  }

  public Horse(int id) {
    this.id = id;
  }

  // public void addPerTime() {
  // this.perTime.clear();
  // int total = 0;
  // int avgTime = totalTime / segment;
  // for (int i = 1; i <= segment - 1; i++) {
  // int addTime = RandCodeUtil.randomBoolean() ? V : -V;
  // if ((avgTime + V) * (segment . - i) + V + total > totalTime) {
  // addTime = -V;
  // }
  // int time = avgTime + addTime;
  // perTime.add(time);
  // total += time;
  // }
  // perTime.add(totalTime - total);
  // }
  /**
   * 添加时间.
   */
  public void addPerTime() {
    this.perTime.clear();
    int total = 0;
    int left = 0;
    // int avgTime = totalTime / segment;
    for (int i = 1; i <= segment - 1; i++) {
      left = N * (segment - i) * V;
      int time = RandCodeUtil.random(N * V, totalTime - left - total);
      perTime.add(time);
      total += time;
    }
    perTime.add(totalTime - total);
  }
}
